<template>
  <el-container>
    <!--头部内容-->
    <el-header>
      <div>
        <img src="../assets/logo1.png" />
        <span>王色儿管理系统</span>
      </div>
      <el-button type="primary">退出</el-button>
    </el-header>
    <el-container>
      <!--左侧内容-->
      <el-aside :width="isCollapse ? '65px' : '250px'">
        <div class="expo" @click="isCollapse=!isCollapse">| | |</div>
        <el-menu
          :uniqueOpened="true"
          :collapse= 'isCollapse'
          :collapse-transition= 'false'
          default-active="1"
          class="el-menu-vertical"
          @open="handleOpen"
          @close="handleClose"
          background-color="#33333f"
          text-color="#fff"
          active-text-color="#409EFF">
          <el-submenu v-for="(item,index) in menuList" :key="item.id" :index="item.id+''">
            <template #title>
              <i :class="iconArray[index]"></i>
              <span>{{ item.authName }}</span>
            </template>
            <!--当前菜单下面的子菜单，子菜单里面的数据在children里面-->
            <el-menu-item :index="'/' + subItem.path" v-for="subItem in item.children" :key="subItem.id">
              <i class="el-icon-menu"></i>
              <span @click="toPath(subItem.path)">{{ subItem.authName }}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "home",

  data(){
    return {
      isCollapse : false,
      menuList: [],
      iconArray:['el-icon-user-solid','el-icon-s-tools','el-icon-s-goods','el-icon-s-order','el-icon-s-data']
    }
  },
  created() {
    this.getMenuList();
  },
  methods: {
    //获取所有的左侧菜单
    getMenuList(){
      this.axios.get('menus').then(data=>{
        console.log(data);
        this.menuList = data.data.data;
      }).catch(err=>{
        console.log(err);
      })
    },
    handleOpen(key, keyPath){
      console.log(key, keyPath);
    },
    handleClose(key, keyPath){
      console.log(key, keyPath);
    },
    //跳转路由
    toPath(path){
      //编程式路由跳转
      this.$router.push(path);
    }
  }
}
</script>

<style scoped>
.el-container{
  height: 100%;
  user-select: none;
}

.el-header{
  display: flex;
  color: #fff;
  background-color: #0f0f0f;
  /*弹性盒模型   左右两边对齐*/
  justify-content: space-between;
  padding-left: 10px;
  /*内容居中对齐*/
  align-items: center;
  font-size: 24px;
}
.el-header div{
  display: flex;
  align-items: center;
}
.el-header div img{
  width: 50px;
  height: 50px;
  border-radius: 50%;
}
.el-header div span{
  margin-left: 20px;
}

/*收缩条*/
.expo{
  background: #4a5064;
  font-size: 10px;
  color: #fff;
  line-height: 24px;
  text-align: center;
  user-select: none;
  cursor: pointer;
}
.el-aside{
  background: #33333f;
  height: 100%;
}
.el-main{
  background: #fff;
}
</style>
